package com.wbao.dianniu.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.ShieldData;
import com.wbao.dianniu.utils.PictureDownloadUtils;

/**
 * 我的屏蔽列表
 * 
 * @author yejianjun
 *
 */
public class ShieldAdapter extends BaseAdapter {
	private Context context;
	private List<ShieldData> mList;
	private LayoutInflater mInflater;

	public ShieldAdapter(Context ctx) {
		context = ctx;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mList = new ArrayList<ShieldData>();
	}

	public void setData(List<ShieldData> list) {
		mList = new ArrayList<ShieldData>();
		mList = list;
	}

	@Override
	public int getCount() {
		if (null == mList)
			return 0;
		else
			return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int index, View convertView, ViewGroup parent) {
		GridHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.shield_list_item, null);   
			holder = new GridHolder();
			holder.imageIV = convertView.findViewById(R.id.shiled_imageview);
			holder.nameTV = convertView.findViewById(R.id.shield_name);
			holder.labelTV = convertView.findViewById(R.id.shield_label);
			convertView.setTag(holder); 
		}else{
			 holder = (GridHolder) convertView.getTag();   
		}
		ShieldData  data = mList.get(index);
		if (data != null) {
			PictureDownloadUtils.displayHeadImage(context,holder.imageIV, data.getHeadPic());
			holder.nameTV.setText(data.getRealName());
			holder.labelTV.setText(data.getLabel());
		}
		
		return convertView;
	}
	
	public class GridHolder {
		public ImageView imageIV;
		public TextView nameTV;
		public TextView labelTV;

//		public ImageView getImageIV() {
//			return imageIV;
//		}
//
//		public void setImageIV(ImageView imageIV) {
//			this.imageIV = imageIV;
//		}
//
//		public TextView getNameTV() {
//			return nameTV;
//		}
//
//		public void setNameTV(TextView nameTV) {
//			this.nameTV = nameTV;
//		}
//
//		public TextView getLabelTV() {
//			return labelTV;
//		}
//
//		public void setLabelTV(TextView labelTV) {
//			this.labelTV = labelTV;
//		}

	}
}
